import math

iterator primes(n: int64): int =
  yield 2
  yield 3

  var k = 6
  while k < n.float.sqrt.int:
    yield k - 1
    yield k + 1
    k.inc 6

proc primeFactors*(n: int64): seq[int] = 
  var x = n
  for i in primes(x):
    while x mod i == 0:
      x = x div i
      result.add i

  if x > 1:
    result.add int(x)